package c.h.a.h0;

import android.content.res.Resources;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import c.h.a.f0.j;
import c.h.a.m0.h;
import c.h.a.m0.i;
import c.h.b.a.a.b;
import c.h.b.a.a.c;
import com.huawei.hms.jos.games.ranking.RankingConst;
import com.liuzh.deviceinfo.DeviceInfoApp;
import com.liuzh.deviceinfo.pro.ProActivity;
import java.text.DecimalFormat;

/* compiled from: SensorDetailFragment */
public class a extends c.h.a.y.a implements SensorEventListener, c.h.a.f0.j.a {
    public float W = 0.0f;
    public ImageView X;
    public TextView Y;
    public TextView Z;
    public TextView b0;
    public TextView c0;
    public TextView d0;
    public TextView e0;
    public TextView f0;
    public TextView g0;
    public TextView h0;
    public TextView i0;
    public TextView j0;
    public TextView k0;
    public TextView l0;
    public TextView m0;
    public ViewGroup n0;
    public int o0 = 0;
    public SensorManager p0;
    public Sensor q0;
    public View r0;
    public ViewGroup s0;

    /* compiled from: SensorDetailFragment */
    public class a extends b {
        public void b() {
            c.f.a.a.a.a.z("ad_sensor_detail");
        }

        public void c(String str) {
            a aVar = a.this;
            if (!aVar.m0()) {
                ProActivity.G(aVar.k());
                aVar.u0();
            }
        }

        public void d(String str) {
            c.f.a.a.a.a.x("ad_sensor_detail", str);
        }

        public void e(View view) {
            if (!a.this.m0()) {
                i iVar = i.a;
                iVar = i.a;
                if (!i.b()) {
                    a aVar = a.this;
                    aVar.s0.removeAllViews();
                    aVar.s0.addView(view);
                    aVar.s0.setVisibility(0);
                    ((View) aVar.s0.getParent()).setVisibility(0);
                }
            }
        }
    }

    public void C(Bundle bundle) {
        this.E = true;
        bundle = this.f;
        if (bundle != null) {
            String str = RankingConst.RANKING_JGW_NAME;
            if (bundle.containsKey(str)) {
                this.c0.setText(bundle.getString(str));
            }
            str = "type";
            if (bundle.containsKey(str)) {
                this.o0 = bundle.getInt(str);
            }
            str = "icon";
            if (bundle.containsKey(str)) {
                this.X.setImageResource(bundle.getInt(str));
            }
        }
        SensorManager sensorManager = (SensorManager) Y().getSystemService("sensor");
        this.p0 = sensorManager;
        if (sensorManager == null) {
            r0();
            return;
        }
        Sensor defaultSensor = sensorManager.getDefaultSensor(this.o0);
        this.q0 = defaultSensor;
        if (defaultSensor == null) {
            r0();
        }
    }

    public void E(Bundle bundle) {
        super.E(bundle);
        j.d.h(this);
    }

    public View G(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        if (this.r0 == null) {
            View inflate = layoutInflater.inflate(2131492964, viewGroup, false);
            this.r0 = inflate;
            this.X = (ImageView) inflate.findViewById(2131296885);
            this.Y = (TextView) this.r0.findViewById(2131297299);
            this.Z = (TextView) this.r0.findViewById(2131297300);
            this.b0 = (TextView) this.r0.findViewById(2131297301);
            this.c0 = (TextView) this.r0.findViewById(2131297283);
            this.d0 = (TextView) this.r0.findViewById(2131297271);
            this.e0 = (TextView) this.r0.findViewById(2131297297);
            this.f0 = (TextView) this.r0.findViewById(2131297298);
            this.g0 = (TextView) this.r0.findViewById(2131297280);
            this.h0 = (TextView) this.r0.findViewById(2131297277);
            this.i0 = (TextView) this.r0.findViewById(2131297275);
            this.j0 = (TextView) this.r0.findViewById(2131297282);
            this.l0 = (TextView) this.r0.findViewById(2131297273);
            this.k0 = (TextView) this.r0.findViewById(2131297272);
            this.m0 = (TextView) this.r0.findViewById(2131297279);
            this.n0 = (ViewGroup) this.r0.findViewById(2131297064);
            this.s0 = (ViewGroup) this.r0.findViewById(2131296331);
        }
        t0();
        return this.r0;
    }

    public void H() {
        this.E = true;
        j.d.j(this);
    }

    public void N() {
        this.E = true;
        this.p0.unregisterListener(this);
    }

    public void P() {
        this.E = true;
        this.p0.registerListener(this, this.q0, 3);
        if (this.q0 != null) {
            Resources resources = DeviceInfoApp.c.getResources();
            this.d0.setText(this.q0.getStringType());
            this.e0.setText(this.q0.getVendor());
            this.f0.setText(String.valueOf(this.q0.getVersion()));
            TextView textView = this.g0;
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(this.q0.getResolution());
            String str = " ";
            stringBuilder.append(str);
            stringBuilder.append(s0());
            textView.setText(Html.fromHtml(stringBuilder.toString()));
            textView = this.h0;
            stringBuilder = new StringBuilder();
            stringBuilder.append(this.q0.getPower());
            stringBuilder.append(resources.getString(2131690061));
            textView.setText(stringBuilder.toString());
            textView = this.i0;
            stringBuilder = new StringBuilder();
            stringBuilder.append(this.q0.getMaximumRange());
            stringBuilder.append(str);
            stringBuilder.append(s0());
            textView.setText(Html.fromHtml(stringBuilder.toString()));
            String string;
            if (VERSION.SDK_INT >= 24) {
                CharSequence string2;
                this.j0.setText(String.valueOf(this.q0.getId()));
                CharSequence string3 = resources.getString(2131690575);
                string = resources.getString(2131690129);
                this.k0.setText(this.q0.isDynamicSensor() ? string3 : string);
                TextView textView2 = this.l0;
                if (!this.q0.isWakeUpSensor()) {
                    string3 = string;
                }
                textView2.setText(string3);
                TextView textView3 = this.m0;
                int reportingMode = this.q0.getReportingMode();
                Resources resources2 = DeviceInfoApp.c.getResources();
                if (reportingMode == 0) {
                    string2 = resources2.getString(2131690227);
                } else if (reportingMode == 1) {
                    string2 = resources2.getString(2131690228);
                } else if (reportingMode == 2) {
                    string2 = resources2.getString(2131690229);
                } else if (reportingMode != 3) {
                    string2 = resources2.getString(2131690514);
                } else {
                    string2 = resources2.getString(2131690230);
                }
                textView3.setText(string2);
                return;
            }
            string = "-";
            this.j0.setText(string);
            this.k0.setText(string);
            this.l0.setText(string);
            this.m0.setText(string);
        }
    }

    public void i(boolean z) {
        if (z) {
            u0();
        } else {
            t0();
        }
    }

    public void onAccuracyChanged(Sensor sensor, int i) {
    }

    public void onSensorChanged(SensorEvent sensorEvent) {
        if (sensorEvent != null && this.p0 != null) {
            DecimalFormat decimalFormat = new DecimalFormat("#0.00");
            Resources resources = DeviceInfoApp.c.getResources();
            int i = this.o0;
            String str = "Z: ";
            String str2 = "Y: ";
            String str3 = "X: ";
            float[] fArr;
            float f;
            float f2;
            float f3;
            TextView textView;
            StringBuilder g;
            TextView textView2;
            StringBuilder g2;
            TextView textView3;
            StringBuilder g3;
            StringBuilder stringBuilder;
            StringBuilder g4;
            TextView textView4;
            if (1 == i || 35 == i || 10 == i || 9 == i) {
                this.n0.setVisibility(0);
                fArr = sensorEvent.values;
                f = fArr[0];
                f2 = fArr[1];
                f3 = fArr[2];
                textView = this.Y;
                g = c.b.a.a.a.g(str3);
                g.append(decimalFormat.format((double) f));
                g.append(resources.getString(2131690081));
                String str4 = "<small><sup>2</sup></small>";
                g.append(str4);
                textView.setText(Html.fromHtml(g.toString()));
                textView2 = this.Z;
                g2 = c.b.a.a.a.g(str2);
                g2.append(decimalFormat.format((double) f2));
                g2.append(resources.getString(2131690081));
                g2.append(str4);
                textView2.setText(Html.fromHtml(g2.toString()));
                textView3 = this.b0;
                g3 = c.b.a.a.a.g(str);
                g3.append(decimalFormat.format((double) f3));
                g3.append(resources.getString(2131690081));
                g3.append(str4);
                textView3.setText(Html.fromHtml(g3.toString()));
            } else if (2 == i || 14 == i) {
                this.n0.setVisibility(0);
                fArr = sensorEvent.values;
                f = fArr[0];
                f2 = fArr[1];
                f3 = fArr[2];
                int i2 = this.o0;
                if (2 == i2) {
                    c.b.a.a.a.w(c.b.a.a.a.g(str3), decimalFormat.format((double) f), resources, 2131690117, this.Y);
                    c.b.a.a.a.w(c.b.a.a.a.g(str2), decimalFormat.format((double) f2), resources, 2131690117, this.Z);
                    c.b.a.a.a.w(c.b.a.a.a.g(str), decimalFormat.format((double) f3), resources, 2131690117, this.b0);
                } else if (14 == i2) {
                    textView = this.Y;
                    stringBuilder = new StringBuilder();
                    stringBuilder.append(resources.getString(2131689943));
                    stringBuilder.append(str3);
                    c.b.a.a.a.w(stringBuilder, decimalFormat.format((double) f), resources, 2131690117, textView);
                    c.b.a.a.a.w(c.b.a.a.a.g(str2), decimalFormat.format((double) f2), resources, 2131690117, this.Z);
                    c.b.a.a.a.w(c.b.a.a.a.g(str), decimalFormat.format((double) f3), resources, 2131690117, this.b0);
                }
            } else if (4 == i || 16 == i) {
                this.n0.setVisibility(0);
                fArr = sensorEvent.values;
                f = fArr[0];
                f2 = fArr[1];
                f3 = fArr[2];
                if (VERSION.SDK_INT >= 26) {
                    textView = this.Y;
                    stringBuilder = new StringBuilder();
                    stringBuilder.append(resources.getString(2131689558));
                    stringBuilder.append(str3);
                    c.b.a.a.a.w(stringBuilder, decimalFormat.format((double) f), resources, 2131690215, textView);
                }
                c.b.a.a.a.w(c.b.a.a.a.g(str2), decimalFormat.format((double) f2), resources, 2131690215, this.Z);
                c.b.a.a.a.w(c.b.a.a.a.g(str), decimalFormat.format((double) f3), resources, 2131690215, this.b0);
            } else if (15 == i || 20 == i || 3 == i || 11 == i) {
                this.n0.setVisibility(0);
                fArr = sensorEvent.values;
                f = fArr[0];
                f2 = fArr[1];
                f3 = fArr[2];
                if (3 == this.o0) {
                    c.b.a.a.a.w(c.b.a.a.a.g(str3), decimalFormat.format((double) f), resources, 2131689788, this.Y);
                    c.b.a.a.a.w(c.b.a.a.a.g(str2), decimalFormat.format((double) f2), resources, 2131689788, this.Z);
                    c.b.a.a.a.w(c.b.a.a.a.g(str), decimalFormat.format((double) f3), resources, 2131689788, this.b0);
                    return;
                }
                TextView textView5 = this.Y;
                g = c.b.a.a.a.g(str3);
                g.append(decimalFormat.format((double) f));
                textView5.setText(g.toString());
                textView5 = this.Z;
                g4 = c.b.a.a.a.g(str2);
                g4.append(decimalFormat.format((double) f2));
                textView5.setText(g4.toString());
                textView5 = this.b0;
                g4 = c.b.a.a.a.g(str);
                g4.append(decimalFormat.format((double) f3));
                textView5.setText(g4.toString());
            } else if (6 == i) {
                textView4 = this.Y;
                g4 = new StringBuilder();
                g4.append(resources.getString(2131690187));
                g4.append(sensorEvent.values[0]);
                g4.append(resources.getString(2131689998));
                textView4.setText(g4.toString());
            } else if (19 == i || 8 == i || 5 == i || 12 == i || 13 == i) {
                TextView textView6;
                this.n0.setVisibility(0);
                if (sensorEvent.sensor.getType() != 12 || sensorEvent.values[0] >= this.p0.getDefaultSensor(8).getMaximumRange()) {
                    textView6 = this.Y;
                    g2 = new StringBuilder();
                    g2.append(resources.getString(2131690207));
                    g2.append(sensorEvent.values[0]);
                    g2.append(resources.getString(2131689756));
                    textView6.setText(g2.toString());
                } else {
                    textView6 = this.Y;
                    g2 = new StringBuilder();
                    g2.append(resources.getString(2131690207));
                    g2.append(sensorEvent.values[0]);
                    g2.append(resources.getString(2131689756));
                    textView6.setText(g2.toString());
                }
                if (sensorEvent.sensor.getType() == 12) {
                    textView6 = this.Y;
                    g = new StringBuilder();
                    g.append(resources.getString(2131689999));
                    g.append(sensorEvent.values[0]);
                    g.append(resources.getString(2131690179));
                    textView6.setText(g.toString());
                    this.W = sensorEvent.values[0];
                }
                if (sensorEvent.sensor.getType() == 5) {
                    textView6 = this.Y;
                    g3 = new StringBuilder();
                    g3.append(resources.getString(2131690003));
                    g3.append(sensorEvent.values[0]);
                    g3.append(resources.getString(2131690058));
                    textView6.setText(g3.toString());
                }
                if (sensorEvent.sensor.getType() == 13) {
                    f = this.W;
                    if (f != 0.0f) {
                        f2 = sensorEvent.values[0];
                        boolean z = h.a;
                        double d = (double) ((f2 * 17.62f) / (f2 + 243.12f));
                        f2 = (float) ((Math.exp(d) * ((double) (((f / 100.0f) * 216.7f) * 6.112f))) / ((double) (f2 + 273.15f)));
                        textView2 = this.Y;
                        StringBuilder stringBuilder2 = new StringBuilder();
                        stringBuilder2.append(resources.getString(2131689499));
                        c.b.a.a.a.w(stringBuilder2, decimalFormat.format((double) f2), resources, 2131690179, textView2);
                        double d2 = (double) (this.W / 100.0f);
                        f = (float) (((Math.log(d2) + d) / (((double) 1099756995) - (Math.log(d2) + d))) * ((double) 1131617976));
                        textView3 = this.Z;
                        g3 = new StringBuilder();
                        g3.append(resources.getString(2131689812));
                        c.b.a.a.a.w(g3, decimalFormat.format((double) f), resources, 2131690179, textView3);
                    }
                }
                if (sensorEvent.sensor.getType() == 19) {
                    textView4 = this.Y;
                    g4 = new StringBuilder();
                    g4.append(resources.getString(2131690401));
                    g4.append(sensorEvent.values[0]);
                    textView4.setText(g4.toString());
                }
            } else {
                this.n0.setVisibility(0);
            }
        }
    }

    public final void r0() {
        if (!m0()) {
            Toast.makeText(Z(), 2131689838, 0).show();
            Y().finish();
        }
    }

    public final String s0() {
        Resources resources = DeviceInfoApp.c.getResources();
        int i = this.o0;
        if (1 == i || 35 == i || 10 == i || 9 == i) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(resources.getString(2131690081));
            stringBuilder.append("<small><sup>2</sup></small>");
            return stringBuilder.toString();
        } else if (2 == i || 14 == i) {
            return resources.getString(2131690117);
        } else {
            if (4 == i || 16 == i) {
                return resources.getString(2131690215);
            }
            if (3 == i) {
                return resources.getString(2131689788);
            }
            if (6 == i) {
                return resources.getString(2131689998);
            }
            if (12 == i) {
                return resources.getString(2131690179);
            }
            if (i == 8) {
                return resources.getString(2131689756);
            }
            if (i == 5) {
                return resources.getString(2131690058);
            }
            return i == 13 ? resources.getString(2131689788) : "";
        }
    }

    public final void t0() {
        i iVar = i.a;
        iVar = i.a;
        if (!i.b() && !c.f.a.a.a.a.u()) {
            c.f.a.a.a.a.y("ad_sensor_detail");
            c.a(Z(), c.h.a.u.a.b, new a());
        }
    }

    public final void u0() {
        this.s0.removeAllViews();
        this.s0.setVisibility(8);
        ((View) this.s0.getParent()).setVisibility(8);
    }
}
